#ifndef __T_TYPES_H
#define __T_TYPES_H

#include "pal/vz_app_common.h"
#include <semaphore.h>
#include <stddef.h>
#include "userLog.h"

typedef signed long long T_INT64;
typedef unsigned long long T_UINT64;
typedef signed int T_INT32;
typedef unsigned int T_UINT32;
typedef signed short T_INT16;
typedef unsigned short T_UINT16;
typedef signed char T_INT8;
typedef unsigned char T_UINT8;

typedef char T_CHAR;
typedef unsigned char T_UCHAR;

typedef void T_VOID;

typedef float T_FLOAT;
typedef double T_DOUBLE;

typedef int T_BOOL;
#define T_TRUE 1
#define T_FALSE 0

typedef void *T_HANDLE;

typedef int (*T_CALLBACK)(void *);

typedef int (*T_FUNC)(unsigned long ulParam);

typedef unsigned long T_ADDR;

#define T_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

#define T_MIN(x, y) ((x) > (y) ? (y) : (x))
#define T_MAX(x, y) ((x) > (y) ? (x) : (y))

#define T_IP_ADDR_LEN (16)

#ifndef __PACKED__
#define __PACKED__ __attribute__((__packed__))
#endif

#define T_ALIGN_FORWARD(size, align) (((T_UINT32)(size) + (align)-1) & (~((align)-1)))

#define T_CHECK_PTR(ptr)           \
    do                             \
    {                              \
        if (!ptr)                  \
        {                          \
            LOG_ERROR("null ptr"); \
            return -1;             \
        }                          \
    } while (0)

#define PRINT_INT(x) LOG_INFO("f:%s(),l:%d->%s:%u", __FUNCTION__, __LINE__, #x, x)
#define PRINT_HEX(x) LOG_INFO("f:%s(),l:%d->%s:0x%x", __FUNCTION__, __LINE__, #x, x)
#define PRINT_STR(x) LOG_INFO("f:%s(),l:%d->%s:%s", __FUNCTION__, __LINE__, #x, x)

typedef struct
{
    IVSRESULT_BIN_T cameraData;
    bool writeable;
} CameraDataCanRead;

typedef struct
{
    sem_t semLaneControl;
    pthread_mutex_t dataMutex;
    CameraDataCanRead cameraData[2];
} SemLaneControlWithMutex;

#endif
